﻿@namespace Masa.Blazor.Presets
@inherits PatternPathComponentBase

<CascadingValue Value="this" IsFixed>
    <MTabs Routable
           Class="@CssProvider.GetClass()"
           Style="@CssProvider.GetStyle()"
           ActiveClass="@ActiveClass"
           HideSlider="@HideSlider"
           SliderColor="@SliderColor"
           @ref="@_tabs">
        @foreach (var patternPath in PatternPaths)
        {
            var pathValue = new PageTabPathValue(patternPath.AbsolutePath, patternPath.AbsolutePath == NavigationManager.GetAbsolutePath());
            var tabOptions = TabOptions?.Invoke(pathValue);
            var tabTitle = GetTabTitle(patternPath, tabOptions);

            <MTab Href="@patternPath.AbsolutePath"
                  Class="@($"{CssProvider.GetClass("tab")} {tabOptions?.Class}")"
                  Exact
                  Ripple="@Ripple"
                  @key="@patternPath.Pattern"
                  @oncontextmenu="(e) => HandleOnContextmenu(e, patternPath)"
                  __internal_preventDefault_oncontextmenu>

                @if (TabIconContent != default)
                {
                    TabIconContent.Invoke(pathValue);
                }
                else if (tabOptions?.Icon != default)
                {
                    <MIcon Size="20">@tabOptions.Icon</MIcon>
                }

                <span class="@CssProvider.GetClass("tab-title") @(tabOptions?.TitleClass)" style="@tabOptions?.TitleStyle">
                    @tabTitle
                </span>

                <MButton Icon
                         Class="@CssProvider.GetClass("tab-close")"
                         OnClick="() => HandleOnCloseTab(patternPath, tabTitle)"
                         Small
                         StopPropagation
                         OnClickPreventDefault>
                    <MIcon Small>@(CloseIcon ?? "mdi-close")</MIcon>
                </MButton>
            </MTab>
        }

        <MMenu @bind-Value="_menuValue"
               Absolute
               OffsetY
               PositionX="@_positionX"
               PositionY="@_positionY"
               CloseOnContentClick>
            <MList Dense>
                @if (TabReload != null)
                {
                    <MListItem OnClick="ReloadTab">@ReloadTabText</MListItem>
                }
                <MListItem OnClick="CloseTabsToTheLeft">@CloseTabsToTheLeftText</MListItem>
                <MListItem OnClick="CloseTabsToTheRight">@CloseTabsToTheRightText</MListItem>
                <MListItem OnClick="CloseOtherTabs">@CloseOtherTabsText</MListItem>
            </MList>
        </MMenu>
    </MTabs>

    @ChildContent
</CascadingValue>
